import {
  createRouter,
  createWebHashHistory,
  createWebHistory,
} from "vue-router";
import routes from "./routes";
import VConsole from "vconsole";

const routerMode = {
  hash: () => createWebHashHistory(),
  history: () => createWebHistory(),
};

const mode = "hash";

const router = createRouter({
  history: routerMode[mode](),
  routes,
  strict: false,
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

router.beforeEach((to, from) => {
  document.title = to.meta.title || "首页";
  if (to.query.vcs) {
    new VConsole();
  }
  return true;
});

router.afterEach(() => {});

router.onError((error) => {
  console.warn("路由错误", error.message);
});

export default router;
